<?php
   class Model_restaurant extends CI_Model{
		protected $_table = "tbl_restaurant";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function getcolunm_allrestaurant($column){
			$this->db->select($column);
			return $this->db->get($this->_table)->result_array();
		}
		public function listall($limit,$start){
			$this->db->limit($limit,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function listall_name(){
			$this->db->select('name');
			return $this->db->get($this->_table)->result_array();
		}
		public function listall_bygetprovide_orname($columnname,$valueofgetname,$limit,$start){
			$query=$this->db->query("select * from tbl_restaurant where ".$columnname." like '%".$valueofgetname."%' order by bestdeal limit ".$start.",".$limit);
			//var_dump("select * from tbl_restaurant where ".$columnname." like '%".$valueofgetname."%' order by bestdeal limit ".$start.",".$limit);
			return $query->result_array();
		}
		public function listall_bygetprovide_orname_orderby($columnname,$valueofgetname,$orderby,$limit,$start){
			$query=$this->db->query("select * from tbl_restaurant where ".$columnname." like '%".$valueofgetname."%' order by ".$orderby." limit ".$start.",".$limit);
			return $query->result_array();
		}
		
		public function listallbyname($name,$limit,$start){
			$this->db->like("name",$name);
			$this->db->limit($limit,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function listallbydestination($destination,$limit,$start){
			$this->db->like("destination",$destination);
			$this->db->limit($limit,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function listtopbyprovide_orderby($limit,$start,$provide,$orderby){						
			$query=$this->db->query("select * from tbl_restaurant where provide like '%".$provide."%' order by ".$orderby." desc limit ".$start.",".$limit);
			return $query->result_array();
		}
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		public function countallbyprovide($provide){
			$query=$this->db->query("select count(*) as total from tbl_restaurant where provide like '%".$provide."%'");
			return $query->row_array();
		}
		public function count_search(){
			$query=$this->db->query("select count(*) as total from tbl_restaurant");
			return $query->row_array();	
		}
		public function get_search_ajax($provide,$name,$sortby,$style,$cuisine,$meal,$limit,$start){
			$limit=" limit ".$start.",".$limit;
			$query="select * from tbl_restaurant ";
			$where=' where 1=1 ';
			if(isset($sortby)) $order=" order by ".$sortby;
			if(isset($provide)) $where.=" and provide like '%".$provide."%' ";	
			if(isset($name) && $name!='') $where.="and name like '%".$name."%'";
			if(isset($style)) $where.= $style;
			if(isset($cuisine)) $where.= $cuisine;
			if(isset($meal)) $where.= $meal;
			$query2=$this->db->query($query.$where.$order.$limit);
			return $query2->result_array();
		}
		
		
		
		//admin
		public function getallbyprovide_name($provide,$name){
			$select="select * from tbl_restaurant ";
			$where=" where 1=1 ";
			$order=" order by name ";
			if($provide!='0') $where.=" and provide like '%".$provide."%'";
			if($name!='') $where.=" and name like '%".$name."%'";
			$query=$this->db->query($select.$where.$order);
			return $query->result_array();
		}
		//used
		public function gettopByprovide_status($provide,$status,$limit,$start){
			$query=$this->db->query("select * from tbl_restaurant where provide like '%".$provide."%' and $status=".$status." order by recommendations limit ".$start.",".$limit);
			return $query->result_array();
		}
		
		public function countbyprovide($provide){
			$query=$this->db->query("select count(*) as total from tbl_restaurant where provide like '%".$provide."%'");
			return $query->row_array();
		}
	}
	?>